package com.nfc.webapp.controllers;

import java.util.List;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.nfc.base.Entity.User;
import com.nfc.base.Service.UserService;

@Controller
public class BdMailerController {


	@Autowired
	UserService userService;

	@RequestMapping(value = "bdMailer", method = RequestMethod.GET)
	public ModelAndView getUsersView() {
		User user = new User();
		//user.setName("Amjad");
		ModelAndView mv = new ModelAndView("usersView");
		mv.addObject("users", userService.getUserList(user));
		mv.addObject("pg_hd","Birth Date Mailer");
		return mv;
	}
	

	@RequestMapping(value = "usersListGetJson", method = RequestMethod.GET)
	public ModelAndView getUsersJson(){

		User user = new User();
		List<User> users = userService.getUserList(user);
		ObjectMapper mapper = new ObjectMapper();
		String json_test = "{ \"total\": \""+(users.size()) + "\", \"items\": ";
		try{
			json_test+=mapper.writeValueAsString(users)+"}";
		
		}catch(Exception e){
			System.out.println(e.toString());
		}

		ModelAndView mv = new ModelAndView("json");
		mv.addObject("json", json_test);
		
		mv.addObject("pg_hd","Birth Date Mailer ~ NFC Portal");
		return mv;
	}
	
	
	
}
